package com.letsiot.applications.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.letsiot.applications.entity.SysUserRole;
import com.letsiot.applications.repository.SysUserRoleMapper;
import com.letsiot.applications.service.SysUserRoleService;
import com.letsiot.common.data.IdUtil;

@Service
public class SysUserRoleServiceImpl implements SysUserRoleService {

    @Autowired
    private SysUserRoleMapper sysUserRoleMapper;

    @Override
    public int save(SysUserRole entity) {
        if (entity.getId() == null) {
            entity.setId(IdUtil.getId());
        }
        return sysUserRoleMapper.insert(entity);
    }

    @Override
    public int delete(Long id) {
        return sysUserRoleMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int update(SysUserRole entity) {
        return sysUserRoleMapper.updateByPrimaryKeySelective(entity);
    }

    @Override
    public SysUserRole findById(Long id) {
        return sysUserRoleMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<SysUserRole> getAll() {
        return sysUserRoleMapper.getAll();
    }

    @Override
    public List<SysUserRole> getByUserId(Long userId) {
        return sysUserRoleMapper.getByUserId(userId);
    }
}
